<template>
	<view class="login">
		<view class="logo">
			<image src="/static/img/logo.png" mode="widthFix"></image>
		</view>
		<button type="default" @click="submit">登录</button>
	</view>
</template>

<script setup>
	import {
		BASE_URL
	} from "@/config/index.js"
	const submit = () => {
		uni.showLoading({
			title: '加载中.',
			mask: true
		})
		uni.getUserProfile({
			provider: 'weixin',
			desc: '用于获取用户信息',
			success: res => {
				if (res.errMsg == 'getUserProfile:ok') {
					let {
						nickName
					} = res.userInfo;
					uni.login({
						success: r => {
							uni.request({
								url: `${BASE_URL}login`,
								data: {
									name: nickName,
									code: r.code
								},
								success: res => {
									uni.setStorageSync('USER_TOKENS', res.data
										.data);
									uni.redirectTo({
										url: '/pages/tabBarPages/home/index'
									})
								}
							});
						}
					});
				}
			},
			complete: () => {
				uni.hideLoading();
			}
		});
	}
</script>

<style lang="scss" scoped>
	.login {
		height: 100vh;
		background: #f0f0f0;
		display: flex;
		align-content: center;
		flex-direction: column;

		.logo {
			width: 250upx;
			height: 54upx;
			margin: 50rpx auto 0;

			image {
				width: 100%;
			}
		}

		button {
			margin: 45% auto auto;
			width: 240rpx;
			background: #b10936;
			font-size: 16px;
			letter-spacing: 10rpx;
			color: #fff;
		}
	}
</style>